/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package project1;

import project1.*;
import project1.*;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
import javax.swing.SwingUtilities;
import javax.swing.table.DefaultTableModel;
import static project1.Frame.*;

/**
 *
 * @author haihip
 */
public class OutBoxView extends javax.swing.JPanel {

    /**
     * Creates new form AnnounceView
     */
    SqlFunc sql = new SqlFunc();
    public OutBoxView(){
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Windows".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
        }
        initComponents();
                
        loadinfo();
        hideAdmin();
        final JPopupMenu popup = new JPopupMenu();
        JMenuItem menuItem = new JMenuItem("Mở Thư",
                new ImageIcon("images/newproject.png"));
        menuItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                try {
                    DefaultTableModel defaultModel = (DefaultTableModel) jTable1.getModel();
                    ResultSet getrs = sql.select("select * from traodoi where ID_TraoDoi='"+defaultModel.getValueAt(jTable1.getSelectedRow(), 0)+"'");
                    if(getrs.next())
                    {
                        ResultSet rsu = sql.select("select ten from user where ID_User="+getrs.getString("ID_RECV"));
                        String nguoiNhan="";
                        if(rsu.next()) nguoiNhan = rsu.getString("ten");
                      
                        tieude.setText(getrs.getString("tieude"));
                        noidung.setText(getrs.getString("noidung"));
                        sender.setText(nguoiNhan);
                        timeSend.setText(getrs.getString("thoigian"));
                        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
                        double width = screenSize.getWidth();
                        double height = screenSize.getHeight();
                        showMailDlg.setLocation((int) (width/2-262), (int) (height/2-300));
                       showMailDlg.show(); 
                       
                    }
                } catch (SQLException ex) {
                    System.out.println("loi doc thu");
                }
            }
        });
        popup.add(menuItem);
        // New File menu item
        
        menuItem = new JMenuItem("Xem thông tin người nhận",new ImageIcon("images/newfile.png"));
        menuItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                 DefaultTableModel defaultModel = (DefaultTableModel) jTable1.getModel();
                ResultSet getrs = sql.select("select ID_RECV from traodoi where ID_TraoDoi='"+defaultModel.getValueAt(jTable1.getSelectedRow(), 0)+"'");
                String ID_RECV="";
                try {
                        if(getrs.next())
                        {
                            ID_RECV = getrs.getString("ID_RECV");
                        }
                        getrs = sql.select("select * from user where ID_User="+ID_RECV);
                        if(!getrs.next()) return;
                        String loai = getrs.getString("loai");
                        String ten = getrs.getString("ten");
                        String gioitinh = getrs.getString("gioitinh");
                        String ngaysinh = getrs.getString("ngaysinh");
                        String email = getrs.getString("email");
                        String quequan = getrs.getString("quequan");
                        String dienthoai = getrs.getString("dienthoai");
                        lblTen.setText(ten);
                        lblGioiTinh.setText(gioitinh);
                        lblNgaySinh.setText(ngaysinh);
                        lblEmail.setText(email);
                        lblQueQuan.setText(quequan);
                        lblPhone.setText(dienthoai);
                        if(loai.equals("1")){
                            getrs = sql.select("select * from sinhvien where ID_User="+ID_RECV);
                            if(!getrs.next()) return;
                            String MSSV=getrs.getString("MSSV");
                            String nganhHoc = getrs.getString("nganhhoc");
                            String khoaHoc = getrs.getString("khoahoc");
                            lblMS.setText("MSSV:");
                            lblMSSV.setText(MSSV);
                            lblEx1.setText("Ngành Học: "+nganhHoc);
                            lblEx2.setText("Khóa Học: "+khoaHoc);
                        }
                        else if(loai.equals("2")){
                            getrs = sql.select("select * from giangvien,BoMon where giangvien.ID_BoMon = bomon.ID_BoMon and ID_User="+ID_RECV);
                            if(!getrs.next()) return;
                            String MSGV = getrs.getString("MSGV");
                            String boMon = getrs.getString("TenBoMon");
                            lblMS.setText("MSGV: ");
                            lblMSSV.setText(MSGV);
                            lblEx1.setText("Bộ Môn: "+boMon);
                            lblEx2.setText("");
                         }
                        else{
                            getrs = sql.select("select * from canbo where ID_User="+ID_RECV);
                            if(!getrs.next()) return;
                            String MSCB = getrs.getString("MSCB");
                            lblMS.setText("MSCB: ");
                            lblMSSV.setText(MSCB);
                            lblEx1.setText("");
                            lblEx2.setText("");
                        }
                        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
                        double width = screenSize.getWidth();
                        double height = screenSize.getHeight();
                        infoSender.setLocation((int) (width/2-262), (int) (height/2-300));
                       infoSender.show(); 
                        
                    } catch (SQLException ex) {
                    System.out.println("khong the get ID nguoi nhan thu");
                }
               
                loadinfo();
            }
        });
        popup.add(menuItem);
        menuItem = new JMenuItem("Xoá thư này",new ImageIcon("images/newfile.png"));
        menuItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                 DefaultTableModel defaultModel = (DefaultTableModel) jTable1.getModel();
                if(!sql.query("delete from traodoi where ID_TraoDoi='"+defaultModel.getValueAt(jTable1.getSelectedRow(), 0)+"'"))
                {
                    System.out.println("Có lỗi xoá Thư");
                }
                loadinfo();
            }
        });
        popup.add(menuItem);
        jTable1.addMouseListener(new MouseAdapter() {
 
            @Override      
            public void mouseClicked(MouseEvent me)
            {
                if(SwingUtilities.isRightMouseButton(me) == true)
                {
                    int row = jTable1.rowAtPoint(me.getPoint());
                    jTable1.clearSelection();
                    jTable1.addRowSelectionInterval(row,row);
                    showPopup(me);
                }
            }
            private void showPopup(MouseEvent e) {
             //   if (e.isPopupTrigger()) {
                    popup.show(e.getComponent(),
                            e.getX(), e.getY());
               // }
            }
        });
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        showMailDlg = new javax.swing.JDialog();
        jPanel3 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        tieude = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        noidung = new javax.swing.JTextArea();
        btnClose = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        sender = new javax.swing.JLabel();
        timeSend = new javax.swing.JLabel();
        infoSender = new javax.swing.JDialog();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        lblMS = new javax.swing.JLabel();
        lblTen = new javax.swing.JLabel();
        lblNgaySinh = new javax.swing.JLabel();
        lblGioiTinh = new javax.swing.JLabel();
        lblQueQuan = new javax.swing.JLabel();
        lblEmail = new javax.swing.JLabel();
        lblPhone = new javax.swing.JLabel();
        lblMSSV = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        lblEx1 = new javax.swing.JLabel();
        lblEx2 = new javax.swing.JLabel();
        CreateMailDlg = new javax.swing.JDialog();
        jLabel19 = new javax.swing.JLabel();
        jLabel20 = new javax.swing.JLabel();
        txtMS = new javax.swing.JTextField();
        lblName = new javax.swing.JLabel();
        jLabel21 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        txtNoiDung = new javax.swing.JTextArea();
        bntSend = new javax.swing.JButton();
        bntCancel = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jLabel22 = new javax.swing.JLabel();
        txtTieuDe = new javax.swing.JTextField();
        jPanel1 = new javax.swing.JPanel();
        btn_home = new javax.swing.JLabel();
        txt_home = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        CreateMail = new javax.swing.JButton();

        showMailDlg.setMinimumSize(new java.awt.Dimension(525, 600));
        showMailDlg.setResizable(false);

        jPanel3.setBackground(new java.awt.Color(255, 255, 255));
        jPanel3.setMaximumSize(new java.awt.Dimension(525, 600));
        jPanel3.setMinimumSize(new java.awt.Dimension(525, 600));
        jPanel3.setPreferredSize(new java.awt.Dimension(525, 600));

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        jLabel1.setText("Xem Chi Tiết Thư");

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        jLabel2.setText("Tiêu đề:");

        tieude.setEditable(false);

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        jLabel3.setText("Nội dung:");

        noidung.setEditable(false);
        noidung.setColumns(20);
        noidung.setRows(5);
        jScrollPane2.setViewportView(noidung);

        btnClose.setText("Đóng");
        btnClose.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCloseActionPerformed(evt);
            }
        });

        jLabel4.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        jLabel4.setText("Thời gian:");

        jLabel5.setText("Người Nhận:");

        sender.setText("ten nguoi nhan");

        timeSend.setText("time");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(tieude))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 487, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 14, Short.MAX_VALUE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel5)
                            .addComponent(jLabel3))
                        .addGap(18, 18, 18)
                        .addComponent(sender, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel4)
                        .addGap(18, 18, 18)
                        .addComponent(timeSend, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(jLabel1)
                .addGap(195, 195, 195))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(btnClose, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(216, 216, 216))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(tieude, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(sender)
                    .addComponent(jLabel4)
                    .addComponent(timeSend))
                .addGap(20, 20, 20)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 318, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(btnClose, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        javax.swing.GroupLayout showMailDlgLayout = new javax.swing.GroupLayout(showMailDlg.getContentPane());
        showMailDlg.getContentPane().setLayout(showMailDlgLayout);
        showMailDlgLayout.setHorizontalGroup(
            showMailDlgLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(showMailDlgLayout.createSequentialGroup()
                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(0, 0, 0))
        );
        showMailDlgLayout.setVerticalGroup(
            showMailDlgLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        infoSender.setResizable(false);

        jLabel6.setFont(new java.awt.Font("Lucida Grande", 1, 14)); // NOI18N
        jLabel6.setText("Thông tin người gửi");

        jLabel7.setText("Họ Tên    :");

        jLabel8.setText("Giới Tính :");

        jLabel9.setText("Quê Quán:");

        jLabel10.setText("Email       :");

        jLabel11.setText("Số ĐT      :");

        jLabel12.setText("Ngày Sinh:");

        lblMS.setText("MSSV:");

        lblTen.setText("jLabel14");

        lblNgaySinh.setText("jLabel14");

        lblGioiTinh.setText("jLabel14");

        lblQueQuan.setText("jLabel14");

        lblEmail.setText("jLabel14");

        lblPhone.setText("jLabel14");

        lblMSSV.setText("jLabel14");

        jButton1.setText("Đóng");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        lblEx1.setText("Ex1");

        lblEx2.setText("Ex2");

        javax.swing.GroupLayout infoSenderLayout = new javax.swing.GroupLayout(infoSender.getContentPane());
        infoSender.getContentPane().setLayout(infoSenderLayout);
        infoSenderLayout.setHorizontalGroup(
            infoSenderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(infoSenderLayout.createSequentialGroup()
                .addGroup(infoSenderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(infoSenderLayout.createSequentialGroup()
                        .addGap(149, 149, 149)
                        .addComponent(jLabel6))
                    .addGroup(infoSenderLayout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addGroup(infoSenderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(infoSenderLayout.createSequentialGroup()
                                .addComponent(jLabel9)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(lblQueQuan, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGroup(infoSenderLayout.createSequentialGroup()
                                .addComponent(jLabel10)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(lblEmail, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGroup(infoSenderLayout.createSequentialGroup()
                                .addComponent(jLabel11)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(lblPhone, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGroup(infoSenderLayout.createSequentialGroup()
                                .addGroup(infoSenderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(infoSenderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, infoSenderLayout.createSequentialGroup()
                                            .addComponent(jLabel12)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                            .addComponent(lblNgaySinh, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, infoSenderLayout.createSequentialGroup()
                                            .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                            .addComponent(lblTen, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                    .addGroup(infoSenderLayout.createSequentialGroup()
                                        .addComponent(jLabel8)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(lblGioiTinh, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(infoSenderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(lblEx1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addGroup(infoSenderLayout.createSequentialGroup()
                                        .addComponent(lblMS)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(lblMSSV, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                    .addGroup(infoSenderLayout.createSequentialGroup()
                                        .addComponent(lblEx2, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(0, 15, Short.MAX_VALUE)))))))
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, infoSenderLayout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addGap(166, 166, 166))
        );
        infoSenderLayout.setVerticalGroup(
            infoSenderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(infoSenderLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(12, 12, 12)
                .addGroup(infoSenderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(infoSenderLayout.createSequentialGroup()
                        .addGroup(infoSenderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel7)
                            .addComponent(lblTen))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(infoSenderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel12)
                            .addComponent(lblNgaySinh))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(infoSenderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel8)
                            .addComponent(lblGioiTinh)))
                    .addGroup(infoSenderLayout.createSequentialGroup()
                        .addGroup(infoSenderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lblMS)
                            .addComponent(lblMSSV))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(infoSenderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblEx1)
                            .addGroup(infoSenderLayout.createSequentialGroup()
                                .addGap(22, 22, 22)
                                .addComponent(lblEx2)))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(infoSenderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(lblQueQuan))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(infoSenderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(lblEmail))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(infoSenderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(lblPhone))
                .addGap(18, 18, 18)
                .addComponent(jButton1)
                .addContainerGap(40, Short.MAX_VALUE))
        );

        CreateMailDlg.setMaximumSize(new java.awt.Dimension(600, 500));
        CreateMailDlg.setMinimumSize(new java.awt.Dimension(600, 500));
        CreateMailDlg.setPreferredSize(new java.awt.Dimension(600, 500));
        CreateMailDlg.setResizable(false);

        jLabel19.setFont(new java.awt.Font("Lucida Grande", 1, 16)); // NOI18N
        jLabel19.setText("Gửi Thư Mới");

        jLabel20.setText("MSSV/MSGV/MSCB Người nhận:");

        txtMS.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtMSKeyPressed(evt);
            }
        });

        lblName.setText(".");

        jLabel21.setText("Nội Dung:");

        txtNoiDung.setColumns(20);
        txtNoiDung.setRows(5);
        jScrollPane3.setViewportView(txtNoiDung);

        bntSend.setText("Gửi Thư");
        bntSend.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bntSendActionPerformed(evt);
            }
        });

        bntCancel.setText("Hủy & Đóng");
        bntCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bntCancelActionPerformed(evt);
            }
        });

        jButton2.setText("Kiểm Tra");
        jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton2MouseClicked(evt);
            }
        });

        jLabel22.setText("Tiêu Đề  :");

        javax.swing.GroupLayout CreateMailDlgLayout = new javax.swing.GroupLayout(CreateMailDlg.getContentPane());
        CreateMailDlg.getContentPane().setLayout(CreateMailDlgLayout);
        CreateMailDlgLayout.setHorizontalGroup(
            CreateMailDlgLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(CreateMailDlgLayout.createSequentialGroup()
                .addGap(32, 32, 32)
                .addGroup(CreateMailDlgLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel21)
                    .addGroup(CreateMailDlgLayout.createSequentialGroup()
                        .addGap(133, 133, 133)
                        .addComponent(bntSend)
                        .addGap(29, 29, 29)
                        .addComponent(bntCancel))
                    .addGroup(CreateMailDlgLayout.createSequentialGroup()
                        .addComponent(jLabel20)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(CreateMailDlgLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel19)
                            .addComponent(lblName, javax.swing.GroupLayout.PREFERRED_SIZE, 315, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(CreateMailDlgLayout.createSequentialGroup()
                                .addComponent(txtMS, javax.swing.GroupLayout.PREFERRED_SIZE, 255, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jButton2))))
                    .addGroup(CreateMailDlgLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addGroup(CreateMailDlgLayout.createSequentialGroup()
                            .addComponent(jLabel22)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(txtTieuDe))
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 541, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(13, Short.MAX_VALUE))
        );
        CreateMailDlgLayout.setVerticalGroup(
            CreateMailDlgLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(CreateMailDlgLayout.createSequentialGroup()
                .addGap(16, 16, 16)
                .addComponent(jLabel19)
                .addGap(12, 12, 12)
                .addGroup(CreateMailDlgLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel20)
                    .addComponent(txtMS, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblName)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(CreateMailDlgLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel22)
                    .addComponent(txtTieuDe, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jLabel21)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 207, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(CreateMailDlgLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(bntSend)
                    .addComponent(bntCancel))
                .addGap(24, 24, 24))
        );

        setBackground(new java.awt.Color(255, 255, 255));
        setMaximumSize(new java.awt.Dimension(1024, 700));
        setMinimumSize(new java.awt.Dimension(1024, 700));

        jPanel1.setBackground(new java.awt.Color(250, 249, 249));
        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel1.setMaximumSize(new java.awt.Dimension(1024, 124));
        jPanel1.setMinimumSize(new java.awt.Dimension(1024, 124));
        jPanel1.setPreferredSize(new java.awt.Dimension(1024, 124));

        btn_home.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        btn_home.setIcon(new javax.swing.ImageIcon(getClass().getResource("/project1/Views/images/home.png"))); // NOI18N
        btn_home.setVerticalAlignment(javax.swing.SwingConstants.TOP);
        btn_home.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        btn_home.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btn_home.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btn_homeMouseClicked(evt);
            }
        });

        txt_home.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        txt_home.setText("Thông tin chung");

        jLabel13.setIcon(new javax.swing.ImageIcon(getClass().getResource("/project1/Views/images/chat.png"))); // NOI18N
        jLabel13.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jLabel13.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel13MouseClicked(evt);
            }
        });

        jLabel14.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel14.setText("Trò Chuyện");

        jLabel15.setIcon(new javax.swing.ImageIcon(getClass().getResource("/project1/Views/images/mail.png"))); // NOI18N
        jLabel15.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jLabel15.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel15MouseClicked(evt);
            }
        });

        jLabel16.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel16.setText("Hòm thư cá nhân");

        jLabel17.setIcon(new javax.swing.ImageIcon(getClass().getResource("/project1/Views/images/send_mail.png"))); // NOI18N
        jLabel17.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jLabel17.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel17MouseClicked(evt);
            }
        });

        jLabel18.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel18.setText("Gửi tin nhắn riêng");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(46, 46, 46)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(btn_home)
                    .addComponent(txt_home))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addComponent(jLabel14, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(jLabel13))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED, 13, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(8, 8, 8)
                        .addComponent(jLabel15))
                    .addComponent(jLabel16))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(47, 47, 47)
                        .addComponent(jLabel17))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(36, 36, 36)
                        .addComponent(jLabel18)))
                .addGap(549, 549, 549))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel15)
                                .addComponent(jLabel17))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel16)
                                .addComponent(jLabel18)))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                            .addComponent(jLabel13)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jLabel14)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(btn_home)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txt_home)))
                .addContainerGap())
        );

        jPanel2.setBackground(new java.awt.Color(255, 255, 255));
        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Các Tin Đã Gửi"));
        jPanel2.setMaximumSize(new java.awt.Dimension(955, 514));
        jPanel2.setMinimumSize(new java.awt.Dimension(955, 514));
        jPanel2.setPreferredSize(new java.awt.Dimension(955, 514));

        jTable1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "ID", "Tiêu đề", "Người Nhận", "Thời gian"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTable1.setRowHeight(24);
        jTable1.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jTable1.getTableHeader().setReorderingAllowed(false);
        jScrollPane1.setViewportView(jTable1);
        jTable1.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        if (jTable1.getColumnModel().getColumnCount() > 0) {
            jTable1.getColumnModel().getColumn(0).setMinWidth(30);
            jTable1.getColumnModel().getColumn(0).setPreferredWidth(30);
            jTable1.getColumnModel().getColumn(0).setMaxWidth(30);
            jTable1.getColumnModel().getColumn(1).setPreferredWidth(300);
        }

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 923, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1)
                .addContainerGap())
        );

        CreateMail.setText("Tạo Thư Mới");
        CreateMail.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CreateMailActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addGap(36, 36, 36)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(CreateMail)
                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(9, 9, 9)
                .addComponent(CreateMail)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 500, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 32, Short.MAX_VALUE))
        );

        jPanel2.getAccessibleContext().setAccessibleName("Hòm Thư Cá Nhân");
        jPanel2.getAccessibleContext().setAccessibleDescription("");
    }// </editor-fold>//GEN-END:initComponents

    private void btn_homeMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btn_homeMouseClicked
        // TODO add your handling code here:
        project1.Frame.setFrame(project1.Frame.homeView);
    }//GEN-LAST:event_btn_homeMouseClicked
    
    void loadinfo()
    {
        DefaultTableModel defaultModel = (DefaultTableModel) jTable1.getModel(); 
        System.out.println(jTable1.getRowCount());
        int num=jTable1.getRowCount();
        for(int i =0;i<num;i++)
        {
            defaultModel.removeRow(0);
        }
        ResultSet rs = sql.select("select * from traodoi where ID_Send="+Project1.User[1]+" order by ID_TraoDoi ASC");
        try {
            while(rs.next())
            {
                ResultSet rsu = sql.select("select ten from user where ID_User="+rs.getString("ID_RECV"));
                String nguoiNhan="";
                if(rsu.next()) nguoiNhan = rsu.getString("ten");
               defaultModel.insertRow(0, new Object [] {rs.getString("ID_TraoDoi"),rs.getString("tieude"), nguoiNhan, rs.getString("thoigian")});
            }
        } catch (SQLException ex) {
            Logger.getLogger(OutBoxView.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    private void btnCloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCloseActionPerformed
        // TODO add your handling code here:
        showMailDlg.hide();
    }//GEN-LAST:event_btnCloseActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        infoSender.dispose();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jLabel13MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel13MouseClicked
        // TODO add your handling code here:
        project1.Frame.setFrame(chatView);
    }//GEN-LAST:event_jLabel13MouseClicked

    private void jLabel15MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel15MouseClicked
        // TODO add your handling code here:
        project1.Frame.setFrame(inboxView);
        inboxView.loadinfo();
    }//GEN-LAST:event_jLabel15MouseClicked

    private void jLabel17MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel17MouseClicked
        // TODO add your handling code here:
        
    }//GEN-LAST:event_jLabel17MouseClicked

    private void CreateMailActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CreateMailActionPerformed
        // TODO add your handling code here:
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
                        double width = screenSize.getWidth();
                        double height = screenSize.getHeight();
                        CreateMailDlg.setLocation((int) (width/2-262), (int) (height/2-300));
                       CreateMailDlg.show(); 
 
    }//GEN-LAST:event_CreateMailActionPerformed

    private void txtMSKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtMSKeyPressed
        // TODO add your handling code here:
        int key = evt.getKeyCode();
        if (key == KeyEvent.VK_ENTER) {
            checkMS();
        }
        
        
    }//GEN-LAST:event_txtMSKeyPressed

    private void jButton2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton2MouseClicked
        // TODO add your handling code here:
        checkMS();
    }//GEN-LAST:event_jButton2MouseClicked

    private void bntSendActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bntSendActionPerformed
        // TODO add your handling code here:
        if(ID_RECV.equals("")){
            JOptionPane.showMessageDialog(null,"Vui lòng nhập đúng MSSV/MSGV/MSCB");
            return;
        }
        if(txtNoiDung.equals("")){
            JOptionPane.showMessageDialog(null,"Vui lòng nhập nội dung thư");
            return;
        }
        String tieude = txtTieuDe.getText();
        String noidung =  txtNoiDung.getText();
        DateFormat dateFormat = new SimpleDateFormat("HH:mm dd/MM/yyyy");
        Calendar cal = Calendar.getInstance();
        
        String thoigian = dateFormat.format(cal.getTime());
        if(sql.query("insert into traodoi (ID_Send,ID_RECV,tieuDe,noiDung,thoigian,status) VALUES('"+Project1.User[1]+"','"+ID_RECV+"','"+tieude+"','"+noidung+"','"+thoigian+"','0')")){
            JOptionPane.showMessageDialog(null,"Gửi Thư thành công!");
            loadinfo();
        }
        else
        {
            JOptionPane.showMessageDialog(null,"Rất tiếc, có lỗi!");
        }
    }//GEN-LAST:event_bntSendActionPerformed

    private void bntCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bntCancelActionPerformed
        // TODO add your handling code here:
        txtTieuDe.setText("");
        txtNoiDung.setText("");
        CreateMailDlg.dispose();
        
    }//GEN-LAST:event_bntCancelActionPerformed
    private String ID_RECV="";
    private void checkMS(){
                    ResultSet rs = sql.select("select ID_User from sinhvien where MSSV='"+txtMS.getText()+"'"
                            + " UNION Select ID_User from giangvien where MSGV='"+txtMS.getText()+"'"
                            + "UNION select ID_User from canbo where MSCB='"+txtMS.getText()+"'");
                    try {
                        if(rs.next()){
                            String ID_User= rs.getString("ID_User");
                            rs = sql.select("select ten from user where ID_User="+ID_User);
                            rs.next();
                            String Name=rs.getString("ten");
                            ID_RECV = ID_User;
                            lblName.setText("ý bạn là: "+Name);
                        }
                        else{
                            lblName.setText("Không thể tìm được thành viên.");
                            ID_RECV="";
                        }
                    } catch (SQLException ex) {
                        System.out.println("loi tim kiem ten nguoi nhan");
                    }
    }
    private void hideAdmin()
    {
       
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton CreateMail;
    private javax.swing.JDialog CreateMailDlg;
    private javax.swing.JButton bntCancel;
    private javax.swing.JButton bntSend;
    private javax.swing.JButton btnClose;
    private javax.swing.JLabel btn_home;
    private javax.swing.JDialog infoSender;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTable jTable1;
    private javax.swing.JLabel lblEmail;
    private javax.swing.JLabel lblEx1;
    private javax.swing.JLabel lblEx2;
    private javax.swing.JLabel lblGioiTinh;
    private javax.swing.JLabel lblMS;
    private javax.swing.JLabel lblMSSV;
    private javax.swing.JLabel lblName;
    private javax.swing.JLabel lblNgaySinh;
    private javax.swing.JLabel lblPhone;
    private javax.swing.JLabel lblQueQuan;
    private javax.swing.JLabel lblTen;
    private javax.swing.JTextArea noidung;
    private javax.swing.JLabel sender;
    private javax.swing.JDialog showMailDlg;
    private javax.swing.JTextField tieude;
    private javax.swing.JLabel timeSend;
    private javax.swing.JTextField txtMS;
    private javax.swing.JTextArea txtNoiDung;
    private javax.swing.JTextField txtTieuDe;
    private javax.swing.JLabel txt_home;
    // End of variables declaration//GEN-END:variables
    private DefaultTableModel model;
}